package com.whfc.fuum.service.impl;

import com.whfc.fuum.dao.AppMeetingMinutesMapper;
import com.whfc.fuum.entity.AppMeetingMinutes;
import com.whfc.fuum.service.AppMeetingMinutesService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * 会议纪要管理Service实现类
 *
 * @author dzg
 * @since 2025-11-21
 */
@DubboService(interfaceClass = AppMeetingMinutesService.class, version = "1.0.0")
public class AppMeetingMinutesServiceImpl implements AppMeetingMinutesService {

    @Autowired
    private AppMeetingMinutesMapper appMeetingMinutesMapper;

    @Override
    public AppMeetingMinutes getById(Integer id) {
        return appMeetingMinutesMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AppMeetingMinutes> list(Integer deptId, String name) {
        return appMeetingMinutesMapper.selectList(deptId, name);
    }

    @Override
    public boolean save(AppMeetingMinutes meetingMinutes) {
        meetingMinutes.setDelFlag(0);
        meetingMinutes.setCreateTime(new Date());
        meetingMinutes.setUpdateTime(new Date());
        return appMeetingMinutesMapper.insert(meetingMinutes) > 0;
    }

    @Override
    public boolean update(AppMeetingMinutes meetingMinutes) {
        meetingMinutes.setUpdateTime(new Date());
        return appMeetingMinutesMapper.updateByPrimaryKey(meetingMinutes) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        AppMeetingMinutes meetingMinutes = getById(id);
        if (meetingMinutes != null) {
            meetingMinutes.setDelFlag(1);
            meetingMinutes.setUpdateTime(new Date());
            return update(meetingMinutes);
        }
        return false;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        // 先逻辑删除
        for (Integer id : ids) {
            delete(id);
        }
        // 物理删除可以在后续清理任务中处理
        return true;
    }
}